package com.qiqidream.admin.common.utils;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * 使用response输出JSON
 *
 * @author : QiQiDream
 * @since : 2019/10/11 17:27
 */
@Slf4j
public class ResponseUtil {

    /**
     * 使用response输出JSON
     */
    public static void out(HttpServletResponse response, String result) {
        PrintWriter out = null;
        try {
            response.setStatus(200);
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/json");
            out = response.getWriter();
            out.println(result);
        } catch (Exception e) {
            log.error(e + "输出JSON出错");
        } finally {
            if (out != null) {
                out.flush();
                out.close();
            }
        }
    }

}
